import cv2 as cv
filename = r'D:\photo\lena.jpg'
img = cv.imread(filename)
gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
cv.imshow('img',img)
cv.imshow('gray',gray)
cv.waitKey()
cv.destroyAllWindows()
'''sobel,两个边界都取一阶差分'''
sobelimg = cv.Sobel(img,-1,dx=1,dy=1,ksize=1)
sobelgray = cv.Sobel(gray,-1,dx=1,dy=1,ksize=1)
cv.imshow('imgresult',sobelimg)
cv.imshow('grayresult',sobelgray)
cv.waitKey()
cv.destroyAllWindows()